<?php
/**
 *
 * User: lang@vip.deyi.com
 * Date: 2018/1/5
 * Time: 15:34
 */

namespace Apps\Weixin\Models;


use Apps\Common\Model\BaseModel;

class WxUserInfo extends BaseModel
{
    // 定义此model访问的数据库名
    protected static $_DBNAME = 'yyx_fanli';

    // 定义此model访问的表名
    protected static $_TABLENAME = 'wx_userinfo';

    public function getOpenIdsByUid($appId, $uids)
    {
        $sql = 'SELECT id AS uid,openid,nickname FROM ' . self::$_TABLENAME . ' WHERE id IN ' . $this->assemblePlaceholders($uids) . ' AND appid=?';

        $values = $uids;
        $values[] = $appId;
        $data = [];
        $res = $this->selectCols($sql, ['uid', 'openid', 'nickname'], $values);

        foreach ($res as $v) {
            $data[$v->uid] = $v;
        }

        return $data;
    }

    public function getOneByUid($appId, $uids)
    {
        $sql = 'SELECT id AS uid,openid,nickname FROM ' . self::$_TABLENAME . ' WHERE id = ? AND appid= ? ';
        $values = $uids;
        $values[] = $appId;
        $res = $this->selectOneCols($sql,['uid', 'openid', 'nickname'],$values);
        return $res;
    }
}